package logic

import (
	"context"
	"user_srv/models/mysql"

	"user_srv/internal/svc"
	"user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHouseListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseListLogic {
	return &HouseListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *HouseListLogic) HouseList(in *user.HouseListRequest) (*user.HouseListResponse, error) {
	// todo: add your logic here and delete this line
	house := mysql.House{}
	list, err := house.HouseList(in.SaraPrice, in.EntPrice)
	if err != nil {
		return nil, err
	}
	var slice []*user.HouseList
	for _, v := range list {
		houseList := user.HouseList{
			HouseName:     v.HouseName,
			HouseFloor:    v.HouseFloor,
			HouseType:     v.HouseType,
			Address:       v.Address,
			HouseCover:    v.HouseCover,
			Area:          v.Area,
			Price:         v.Price,
			HouseDescribe: v.HouseDescribe,
			HouseId:       v.HouseStatus,
			HouseStatus:   v.HouseStatus,
		}
		slice = append(slice, &houseList)
	}
	return &user.HouseListResponse{
		List: slice,
	}, nil
}
